import React from 'react'
import Loadable from 'react-loadable'

// 这是在路由切换时要动态加载组件时的中转组件
function Loading(props) {
  if (props.error) {
    return <div>Error! <button onClick={props.retry}>Retry</button></div>
  } else if (props.pastDelay) {
    return <div>Loading...</div>
  } else {
    return null
  }
}

const withLoadable = (loader) => Loadable({
  loader, // () => import('path')
  loading: Loading,
})

export default withLoadable
